Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blank screen is shown when opening a report screen after relaunching app #37596

Merged

Conversation

bernhardoj
Copy link
Contributor

Details

The withOnyx returns null when the data is still loading. We already put some initialValue to the required onyx data, but Onyx has a bug that doesn't accept falsey initialValue. This PR also fixes some App issue that arise after fixing the onyx bug.

Fixed Issues

$ #35906
PROPOSAL: #35906 (comment)

Tests

Same as QA Steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA Steps

QA Steps

A.

  1. Close the app if it's opened
  2. Reopen the app
  3. Open any chat
  4. Do step 3 on several chats
  5. Verify the chat screen/skeleton is shown instead of blank screen for a brief moment

B.

  1. Open a workspace chat
  2. Turn off internet connection
  3. Request money from the workspace
  4. Open the transaction thread
  5. Verify you are able to see the transaction thread details instead of infinite loading

C.

  1. Create a new workspace room
  2. Verify you are navigated to the workspace room chat and not to concierge chat
  3. Verify the room name is correct
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2024-02-14.at.13.58.29.mov
New.Expensify.Dev.1.mp4
Android: mWeb Chrome
Screen.Recording.2024-02-14.at.14.01.06.mov
Screen.Recording.2024-02-27.at.16.05.34.mov
iOS: Native
Screen.Recording.2024-02-14.at.14.05.55.mov
Screen.Recording.2024-02-27.at.15.59.42.mov
iOS: mWeb Safari
Screen.Recording.2024-02-14.at.14.01.41.mov
Screen.Recording.2024-02-27.at.15.54.32.mov
MacOS: Chrome / Safari
Screen.Recording.2024-02-14.at.14.06.30.mov
Screen.Recording.2024-02-27.at.15.48.19.mov
MacOS: Desktop
Screen.Recording.2024-02-14.at.14.07.33.mov
Screen.Recording.2024-02-27.at.15.50.39.mov

@bernhardoj bernhardoj requested a review from a team as a code owner March 1, 2024 11:54
@melvin-bot melvin-bot bot removed the request for review from a team March 1, 2024 11:54
Copy link

melvin-bot bot commented Mar 1, 2024

@ntdiary Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot requested a review from ntdiary March 1, 2024 11:54
if (isEmptyObject(report)) {
optimisticData[0].onyxMethod = Onyx.METHOD.SET;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix all the found issues from our PR
#37247, #37234, #37300, and #37251.

The root cause is explained here

@bernhardoj
Copy link
Contributor Author

There are 2 issues left however and they have the same issue too.

  1. Chat Report is shown as the report name when creating a new workspace room
image

The report name is overwritten with the default name here because the onyx data is not ready yet.

const optimisticReport = reportActionsExist(reportID)
? {}
: {
reportName: allReports?.[reportID]?.reportName ?? CONST.REPORT.DEFAULT_REPORT_NAME,
};

  1. OpenReport is still called even though we have a comment here mentioning that we use SET so the report data is available immediately

    App/src/libs/actions/Report.ts

    Lines 1767 to 1770 in 39a257d

    // Onyx.set is used on the optimistic data so that it is present before navigating to the workspace room. With Onyx.merge the workspace room reportID is not present when
    // fetchReportIfNeeded is called on the ReportScreen, so openReport is called which is unnecessary since the optimistic data will be stored in Onyx.
    // Therefore, Onyx.set is used instead of Onyx.merge.
    const optimisticData: OnyxUpdate[] = [

so we can avoid calling OpenReport.

// It possible that we may not have the report object yet in Onyx yet e.g. we navigated to a URL for an accessible report that
// is not stored locally yet. If report.reportID exists, then the report has been stored locally and nothing more needs to be done.
// If it doesn't exist, then we fetch the report from the API.
if (report.reportID && report.reportID === getReportID(route) && !isLoadingInitialReportActions) {
return;
}
Report.openReport(reportIDFromPath);

However, the report data is not available immediately.

The optimisticData is updated through Onyx.update calls which use promises that delay the operation.
https://github.com/Expensify/react-native-onyx/blob/034aa0e7858ec4f8a859117b5f527c793b0a61f7/lib/Onyx.js#L1494-L1518

We can fix this using Onyx.set or Onyx.multiSet directly, so the report (and other required data) is 100% immediately available. So far, I have used this in Report.openReport and Report.addPolicyReport, and it works well. What do you think?

@ntdiary
Copy link
Contributor

ntdiary commented Mar 6, 2024

Just finished several pending migration PRs in these days, I expect to have time tomorrow to revisit the above problems. :)

@ntdiary
Copy link
Contributor

ntdiary commented Mar 11, 2024

Still investigating the related issues.

@bernhardoj
Copy link
Contributor Author

Or perhaps we should remove the allowStaleData because the component expects the report data to be available (not pending to set/merge) when mounted. So far I can't notice the blank screen after removing it and returning undefined from reportWithoutHasDraftSelector instead of null.

@ntdiary
Copy link
Contributor

ntdiary commented Apr 9, 2024

Or perhaps we should remove the allowStaleData because the component expects the report data to be available (not pending to set/merge) when mounted. So far I can't notice the blank screen after removing it and returning undefined from reportWithoutHasDraftSelector instead of null.

Hi, @bernhardoj, Did you mean that we only need to remove allowStaleData in ReportScreen? I can still get a black screen. 🤔

We can fix this using Onyx.set or Onyx.multiSet directly, so the report (and other required data) is 100% immediately available.

As for this part, we had a discussion in other places and felt that it is better to avoid using the set method as much as possible, so I wanted to investigate if there are other solutions. :)

@bernhardoj
Copy link
Contributor Author

Hmm, the only idea left I have is to replace withOnyx with useOnyx hook.

@ntdiary
Copy link
Contributor

ntdiary commented Apr 12, 2024

Hmm, the only idea left I have is to replace withOnyx with useOnyx hook.

Thank you! I'll investigate this solution next week.

@ntdiary
Copy link
Contributor

ntdiary commented Apr 19, 2024

I'm experimenting with switching to useOnyx today, and it feels like a promising direction. However, we still need to consider a fair number of cases and performance, will continue to delve deeper over the weekend, and expect to provide further updates next Monday.

@ntdiary
Copy link
Contributor

ntdiary commented Apr 22, 2024

test.mp4

The investigation into the issue is still progressing slowly. It seems there is still some delay when the report is opened first. In my previous tests, there have been instances where the skeleton didn't appear immediately, and sometimes the header didn't show up right away either. This week, I'll focus on this issue and another refocusing issue. Also, if necessary, will seek more inputs in the performance channel. :)

@bernhardoj
Copy link
Contributor Author

Based on the video, looks like the report screen is rendered immediately as shown by the (broken) composer, I will check it too tomorrow to see if I can reproduce and find something about it.

@ntdiary
Copy link
Contributor

ntdiary commented Apr 25, 2024

reportName: allReports?.[reportID]?.reportName ?? CONST.REPORT.DEFAULT_REPORT_NAME,

This line of code was introduced here, and I'm also testing to remove it.
#12157 (comment)

@ntdiary
Copy link
Contributor

ntdiary commented Apr 29, 2024

So far, using useOnyx has indeed significantly improved screen loading speed. However, there are still some potential bugs to be aware of (e.g., in my last case, I encountered an infinite loop when opening no.1's Workspace. But it could also be a problem with my own code logic, which needs further verification). Additionally, considering the complexity of this issue, I may later ask on Slack if it's possible to increase the bounty for this issue. 😄

Regarding the broken composer, I think it also occurs in the production environment, so we can ignore it for now.

test.mp4

@bernhardoj
Copy link
Contributor Author

This line of code was introduced here, and I'm also testing to remove it.

I think we can keep it like that. To solve the name issue in my comment here, I update the code to call OpenReport only after the report onyx is loaded. I think we can convert only some of the onyx data to useOnyx to reduce the risk of regression. I have pushed the update so you can compare and test it.

@ntdiary
Copy link
Contributor

ntdiary commented May 14, 2024

I think we can keep it like that. To solve the name issue in my comment #37596 (comment), I update the code to call OpenReport only after the report onyx is loaded. I think we can convert only some of the onyx data to useOnyx to reduce the risk of regression. I have pushed the update so you can compare and test it.

Vacation is over, time to tackle this challenge again. 😂 In my test, the middle list area still shows a blank screen. maybe we can show the skeleton instead?

test.mp4

@bernhardoj
Copy link
Contributor Author

Ok I can reproduce the blank list. I checked the onyx data of ReportActionsView

withOnyx<ReportActionsViewProps, ReportActionsViewOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
transactionThreadReportActions: {
key: ({transactionThreadReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`,
canEvict: false,
selector: (reportActions: OnyxEntry<OnyxTypes.ReportActions>) => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions, true),
},
transactionThreadReport: {
key: ({transactionThreadReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`,
},

and it's the transactionThreadReport that's not available yet, so I set the initial value to it.

@@ -489,6 +467,16 @@ function ReportScreen({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
// Call OpenReport only if we are not linking to a message or the report is not available yet
if (reportResult.status === 'loading' || (reportActionIDFromRoute && report.reportID)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better now! Also, just a minor change request, we have an isLoadingOnyxValue util function, so defining a variable might be better than using reportResult.status directly.(e.g., const isLoadingReportOnyx = isLoadingOnyxValue(reportResult), which will help clean up the logic of this component in the future. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice one. Updated.

@bernhardoj
Copy link
Contributor Author

Btw, I'm still considering whether to include the report onyx loading state to isLoading here

const isLoading = !reportIDFromRoute || (!isSidebarLoaded && !isReportOpenInRHP) || PersonalDetailsUtils.isPersonalDetailsEmpty();

I think we should add it. Do you agree?

@ntdiary
Copy link
Contributor

ntdiary commented May 17, 2024

Btw, I'm still considering whether to include the report onyx loading state to isLoading here

const isLoading = !reportIDFromRoute || (!isSidebarLoaded && !isReportOpenInRHP) || PersonalDetailsUtils.isPersonalDetailsEmpty();

I think we should add it. Do you agree?

I've also attempted something similar before. This might involve cleaning up the loading related code. I'll first ask about it on Slack. :)

@ntdiary
Copy link
Contributor

ntdiary commented May 23, 2024

Hi @bernhardoj, after discussion, we've decided not to make further changes for now, The loading and other withOnyx improvement can be addressed in another ticket later. Do you mind merging the main branch to pass the ts check(I know the error isn't caused by this PR)? :)

@bernhardoj
Copy link
Contributor Author

Thanks for the updated! Merged with main

@ntdiary
Copy link
Contributor

ntdiary commented May 23, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
37596-android-native.mp4
Android: mWeb Chrome
37596-android-chrome.mp4
iOS: Native
37596-ios-native.mp4
iOS: mWeb Safari
37596-ios-safari.mp4
MacOS: Chrome / Safari
37596-web.mp4
MacOS: Desktop
37596-desktop.mp4

Copy link
Contributor

@ntdiary ntdiary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. :)
Additionally, A and C are online cases, B is offline. And B, C are regression cases that were reported previously.

B.mp4
C.mp4

@ntdiary
Copy link
Contributor

ntdiary commented May 23, 2024

All yours, @yuwenmemon. I haven't returned to the assignment queue, so the automatic assignment hasn't taken effect. :)

@yuwenmemon yuwenmemon self-requested a review May 24, 2024 00:20
@yuwenmemon
Copy link
Contributor

Thanks!

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/yuwenmemon in version: 1.4.77-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.77-11 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.4.77-11 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants